import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store/index.js'

import HomeMain from "../components/home/main_component.vue"
import UserLogin from "../components/home/login_component.vue"
import UserInfo from "../components/home/userinfo_component.vue";

import SubjectMain from "../components/subject/main_component.vue"
import SubjectList from "../components/subject/list_component.vue"
import SubjectAdd from "../components/subject/add_component.vue"
import SubjectModify from "../components/subject/modify_component.vue"
import SubjectView from "../components/subject/view_component.vue"

import StageMain from "../components/stage/main_component.vue"
import StageList from "../components/stage/list_component.vue"
import StageAdd from "../components/stage/add_component.vue"
import StageBatchAdd from "../components/stage/batchadd_component.vue"
import StageModify from "../components/stage/modify_component.vue"
import StageView from "../components/stage/view_component.vue"

import QuestionTypeMain from "../components/questiontype/main_component.vue"
import QuestionTypeList from "../components/questiontype/list_component.vue"
import QuestionTypeAdd from "../components/questiontype/add_component.vue"
import QuestionTypeModify from "../components/questiontype/modify_component.vue"
import QuestionTypeView from "../components/questiontype/view_component.vue"

import DifficultyMain from "../components/difficulty/main_component.vue"
import DifficultyList from "../components/difficulty/list_component.vue"
import DifficultyAdd from "../components/difficulty/add_component.vue"
import DifficultyModify from "../components/difficulty/modify_component.vue"
import DifficultyView from "../components/difficulty/view_component.vue"

import QuestionMain from "../components/question/main_component.vue"
import QuestionList from "../components/question/list_component.vue"
import QuestionAdd from "../components/question/add_component.vue"
import QuestionModify from "../components/question/modify_component.vue"
import QuestionView from "../components/question/view_component.vue"

import PaperMain from "../components/paper/main_component.vue"

import PaperRecordMain from "../components/paperrecord/main_component.vue"
import PaperRecordList from "../components/paperrecord/list_component.vue"

import AnalyzePaperMain from "../components/analyzepaper/main_component.vue"

Vue.use(VueRouter);

//路由定义
const routes = [
    {
        path: '/home',
        name: 'Home',
        component: HomeMain
    },
    {
        path: '/login',
        name: 'Login',
        component: UserLogin
    },
    {
        path: "/userinfo",
        name: "UserInfo",
        component: UserInfo
    },
    {
        path: '/subject',
        name: 'SubjectHome',
        component: SubjectMain,
        children: [
            {
                name: "subjectlist",
                path: "list",
                component: SubjectList
            },
            {
                name: "subjectadd",
                path: "add",
                component: SubjectAdd
            },
            {
                name: "subjectmodify",
                path: "modify/:id",
                component: SubjectModify,
                props: true
            },
            {
                name: "subjectview",
                path: "view/:id",
                component: SubjectView,
                props: true
            },
            { path: "", redirect: "/subject/list" }
        ]
    },
    {
        path: '/stage',
        name: 'StageHome',
        component: StageMain,
        children: [
            {
                name: "stagelist",
                path: "list",
                component: StageList
            },
            {
                name: "stageadd",
                path: "add",
                component: StageAdd
            },
            {
                name: "stagemodify",
                path: "modify/:id",
                component: StageModify,
                props: true
            },
            {
                name: "stageview",
                path: "view/:id",
                component: StageView,
                props: true
            },
            {
                name: "stagebatchadd",
                path: "batchadd",
                component: StageBatchAdd
            },
            { path: "", redirect: "/stage/list" }
        ]
    },
    {
        path: '/questiontype',
        name: 'QuestionTypeHome',
        component: QuestionTypeMain,
        children: [
            {
                name: "questiontypelist",
                path: "list",
                component: QuestionTypeList
            },
            {
                name: "questiontypeadd",
                path: "add",
                component: QuestionTypeAdd
            },
            {
                name: "questiontypemodify",
                path: "modify/:id",
                component: QuestionTypeModify,
                props: true
            },
            {
                name: "questiontypeview",
                path: "view/:id",
                component: QuestionTypeView,
                props: true
            },
            { path: "", redirect: "/questiontype/list" }
        ]
    },
    {
        path: '/difficulty',
        name: 'DifficultyHome',
        component: DifficultyMain,
        children: [
            {
                name: "difficultylist",
                path: "list",
                component: DifficultyList
            },
            {
                name: "difficultyadd",
                path: "add",
                component: DifficultyAdd
            },
            {
                name: "difficultymodify",
                path: "modify/:id",
                component: DifficultyModify,
                props: true
            },
            {
                name: "difficultyview",
                path: "view/:id",
                component: DifficultyView,
                props: true
            },
            { path: "", redirect: "/difficulty/list" }
        ]
    },
    {
        path: '/question',
        name: 'QuestionHome',
        component: QuestionMain,
        children: [
            {
                name: "questionlist",
                path: "list",
                component: QuestionList
            },
            {
                name: "questionadd",
                path: "add",
                component: QuestionAdd
            },
            {
                name: "questionmodify",
                path: "modify/:id",
                component: QuestionModify,
                props: true
            },
            {
                name: "questionview",
                path: "view/:id",
                component: QuestionView,
                props: true
            },
            { path: "", redirect: "/question/list" }
            ,
        ]
    },
    {
        path: '/paperrecord',
        name: 'PaperRecordHome',
        component: PaperRecordMain,
        children: [
            {
                name: "paperrecordlist",
                path: "list",
                component: PaperRecordList
            },
            // {
            //     name: "questionview",
            //     path: "view/:id",
            //     component: QuestionView,
            //     props: true
            // },
            { path: "", redirect: "/paperrecord/list" }
            ,
        ]
    },
    {
        path: '/paper',
        name: 'PaperMain',
        component: PaperMain,
    },
    {
        path: '/analyzepaper',
        name: 'AnalyzePaperMain',
        component: AnalyzePaperMain,
    },
    { path: "", redirect: "/login" }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: routes
})

router.beforeEach((to, form, next) => {
    if (to.name != "Login" && store.getters.getLoginUser == null) {
        next("Login");
    } else {
        next();
    }
});


export default router;
